package logic

import (
	"context"
	"go.uber.org/zap"
	"week1/textrpc/service"

	"week1/textrpc/internal/svc"
	"week1/textrpc/textrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type TextDataLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewTextDataLogic(ctx context.Context, svcCtx *svc.ServiceContext) *TextDataLogic {
	return &TextDataLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *TextDataLogic) TextData(in *textrpc.TextDataReq) (*textrpc.TextDataRes, error) {
	// todo: add your logic here and delete this line
	text, err := service.GetTextById(int(in.Id))
	if err != nil {
		return &textrpc.TextDataRes{Data: nil}, err
	}
	data := &textrpc.TextData{
		Id:        int32(text.ID),
		Title:     text.Title,
		Comment:   text.Comment,
		TypeId:    int32(text.TypeId),
		Tag:       text.Tag,
		LookCount: int32(text.LookCount),
		Status:    int32(text.Status),
	}
	zap.S().Info("查询成功")
	return &textrpc.TextDataRes{Data: data}, nil
}
